package day06;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class Demo01 {
    public static void main(String[] args) throws Exception {
        /*
         * ArrayList 不能并发修改
         */
        //ArrayList<String> list = new ArrayList<>();
        List<String> list = new CopyOnWriteArrayList<>();
        list.add("Tom");
        list.add("Jerry");
        list.add("Andy");
        list.add("Mac");
        Thread t1 = new Thread(){
            @Override
            public void run() {
                try {
                    sleep(1000);
                    list.add(0, "Wang");
                    System.out.println(list);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        t1.start();
        for (String name: list) {
            System.out.println(name);
            Thread.sleep(1000);
        }
    }
}
